package pl.streamsoft.currencyApp.stream;

import java.io.InputStream;
import java.util.Scanner;

public class InputStreamReader implements IStream {

	private String charsetName;
	private InputStream inputStream;
	private Scanner sc;
	
	public InputStreamReader(InputStream inputStream, String charsetName){
		this.charsetName = charsetName;
		this.inputStream = inputStream;
	}

	/**
	 * Gets string file from url (InputStream)
	 * using charsetName by default "ISO-8859-2"
	 * and delimiter "\A"
	 */
	@Override
	public String getFile(){
		sc = new Scanner(inputStream, charsetName);
		//  Reading from begining to end of stream. Scanner will fetch the whole stream in one move!
		String out = sc.useDelimiter("\\A").next();
		return out;	
	}
	
	public String getCharsetName() {
		return charsetName;
	}
}
